package com.qls.web.modules.dt.controller;

import com.qls.core.entity.DtDt;
import com.qls.core.utils.R;
import com.qls.web.common.utils.PageUtils;
import com.qls.web.modules.dt.service.DtService;
import com.qls.web.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 分销商
 *
 * @author yj
 * @email yj@gmail.com
 * @date 2021-09-04 12:10:22
 */
@RestController
@RequestMapping("dt/dt")
public class DtController extends AbstractController {
    @Autowired
    private DtService dtService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("dt:dt:list")
    public R list(@RequestParam Map<String, Object> params) {
        params.put("dtId", getUserDtId());
        PageUtils page = dtService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("dt:dt:info")
    public R info(@PathVariable("id") Long id) {
        DtDt dt = dtService.getById(id);

        return R.ok().put("dt", dt);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("dt:dt:save")
    public R save(@RequestBody DtDt dt) {
        dtService.save(dt);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("dt:dt:update")
    public R update(@RequestBody DtDt dt) {
        dtService.updateById(dt);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("dt:dt:delete")
    public R delete(@RequestBody Long[] ids) {
        dtService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
